#ifndef __CWin_h__
#define __CWin_h__

#include <windows.h>
#include "dkglPreRequest.h"
#include "dkglController.h"

namespace CAIG
{

class CWin
{
public:

	bool init();
	void go();

	CWin();
	/*CWin(bool useBkgr = false, bool useTimer = true);
	CWin(DWORD style, bool useBkgr = false, bool useTimer = true);
	CWin(int width = CW_USEDEFAULT, int height = CW_USEDEFAULT, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, bool useBkgr = false, bool useTimer = true);
	CWin(DWORD style, int width = CW_USEDEFAULT, int height = CW_USEDEFAULT, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, bool useBkgr = false, bool useTimer = true);*/
	virtual ~CWin() {};

protected:

	virtual inline void OnCreate()  {};
	virtual inline void OnPaint()   {};
	virtual inline void OnSize(WORD width, WORD height) {};
	virtual inline void OnTime()    {};
	virtual inline void OnDestroy() {};

	virtual void render()
	{
		
	}

	virtual void update()
	{

	}

	virtual void KeyDown()
	{

	}
	virtual void KeyUp()   {}

	inline void plugMouse(DKGL::MouseVF *mouse)
	{mMousePtr = mouse;};

	//virtual inline void LeftDown  (WORD x, WORD y) { mLeftMB  = MB_DOWN; mX = x; mY = y; };
	//virtual inline void RightDown (WORD x, WORD y) { mRightMB = MB_DOWN; mX = x; mY = y; };
	//virtual inline void LeftUp    (WORD x, WORD y) { mLeftMB  = MB_UP;   mX = x; mY = y; };
	//virtual inline void RightUp   (WORD x, WORD y) { mRightMB = MB_UP;   mX = x; mY = y; };
	//virtual inline void Drag      (WORD x, WORD y) { mX = x; mY = y; };

	// call these functions before init
	inline void useBkgr (bool use) { hasBkgr  = use; };
	inline void useTimer(bool use) { hasTimer = use; };

	inline void setWindowStyle (DWORD style) { dwStyle = style; };
	inline void setWindowSize  (int width, int height) { mWndWidth = width; mWndHeight = height; };
	inline void setWindowPos   (int x, int y) { mWndPosX = x; mWndPosY = y; };

	float	getTimeInSec() const;

	int		mWndWidth, mWndHeight;
	int		mWndPosX, mWndPosY;

	bool	mKeys[256];
	//WORD	mLeftMB, mRightMB;
	//WORD	mX, mY;

	//static const WORD	MB_UP = 0;
	//static const WORD	MB_DOWN = 1;

	HWND	hWnd;
	HDC		hDC;

private:

	DKGL::MouseVF *mMousePtr, mDummyMouse;

	bool	hasBkgr;
	bool	hasTimer;
	DWORD	dwStyle;
	float	mTicksPerSec;

	LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
	static LRESULT CALLBACK StaticWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
};

}

#endif
